/**
 * 商品管理路由模块
 * 
 * 实现商品增删改查(CRUD)操作:
 * 1. GET /api/goods/list/{page}/{limit}?category1Id={category1Id}&category2Id={category2Id}&tag={tag} - 获取商品列表（支持分页、分类筛选和标签筛选）
 * 2. GET /api/goods/:id - 获取商品详情
 * 3. POST /api/goods - 创建商品（请求体中包含 tags 字段）
 * 4. PUT /api/goods/:id - 更新商品（请求体中可包含 tags 字段）
 * 5. DELETE /api/goods/:id - 删除商品
 * 6. GET /api/goods/recommended - 获取人气推荐商品（基于商品标签或销量等）
 * 7. GET /api/goods/guess-like - 获取猜你喜欢商品
 * 8. GET /api/goods/tags/search - 获取所有已使用的不重复标签列表
 */

//引入express模块
const express = require("express");

//创建路由对象
const router = express.Router();

//引入商品控制器
const goodsController = require("../controllers/goods.controller");

// 引入公共的异步错误处理工具函数
const asyncHandler = require("../utils/asyncHandler");

/**
 * @route   GET /api/goods/list/:page/:limit
 * @desc    获取商品列表（支持分页、分类筛选和标签筛选）
 * @access  Public
 */
router.get("/list/:page/:limit", asyncHandler(goodsController.getGoodsList));

/**
 * @route   GET /api/goods/recommended
 * @desc    获取人气推荐商品
 * @access  Public
 */
router.get("/recommended", asyncHandler(goodsController.getRecommendedGoods));

/**
 * @route   GET /api/goods/guess-like
 * @desc    获取猜你喜欢商品
 * @access  Public
 */
router.get("/guess-like", asyncHandler(goodsController.getGuessLikeGoods));

/**
 * @route   GET /api/goods/tags/search
 * @desc    获取所有已使用的不重复标签列表
 * @access  Public
 */
router.get("/tags/search", asyncHandler(goodsController.getAllTags));

/**
 * @route   GET /api/goods/:id
 * @desc    获取商品详情
 * @access  Public
 */
router.get("/:id", asyncHandler(goodsController.getGoodsById));

/**
 * @route   POST /api/goods
 * @desc    创建商品
 * @access  Public
 */
router.post("/", asyncHandler(goodsController.createGoods));

/**
 * @route   PUT /api/goods/:id
 * @desc    更新商品
 * @access  Public
 */
router.put("/:id", asyncHandler(goodsController.updateGoods));

/**
 * @route   DELETE /api/goods/:id
 * @desc    删除商品
 * @access  Public
 */
router.delete("/:id", asyncHandler(goodsController.deleteGoods));

module.exports = router;